<?php
/*
+-----------------------------------------------------------------------------+
| $Id: function.smarty.php 2010-05-24 11:45:43Z Bleakwind $
| Private Smarty function
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
| Release under the GNU Lesser General Public License Version 3 (LGPLv3):
|   http://www.gnu.org/licenses/lgpl.html
+-----------------------------------------------------------------------------+
*/

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.return_article_info.php
 * Type:     function
 * Name:     return_article_info
 * Purpose:  return article_info
 * -------------------------------------------------------------
 */
function smarty_function_return_article_info($params, &$smarty)
{
    global $sys;
    $_output = '';

    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'item':
                $item = (string)$_val;
                break;
            case 'article_id':
                $article_id = (int)$_val;
                break;
            default:
                $smarty->trigger_error("return_article_info: unknown attribute '$_key'");
        }
    }
    if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
        $smarty->trigger_error("return_article_info: missing 'item' attribute");
    }
    if ( $article_id == "0") {
        $smarty->trigger_error("return_article_info: missing 'article_id' attribute");
    }
    $smarty->assign($item, $sys->return_article_info($article_id));
    return;
}
$t->register_function("return_article_info", "smarty_function_return_article_info");

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.return_article_list.php
 * Type:     function
 * Name:     return_article_list
 * Purpose:  return article_list
 * -------------------------------------------------------------
 */
function smarty_function_return_article_list($params, &$smarty)
{
    global $sys;
    $_output            = '';
    $condition          = array();
    $list_article_id  = array();

    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'item':
                $item = (string)$_val;
                break;
            case 'article_id':
                $article_id = (string)$_val;
                break;
            case 'except_article_id':
                $except_article_id = (string)$_val;
                break;
            case 'cover':
                $cover = (int)$_val;
                break;
            case 'if_top':
                $if_top = (int)$_val;
                break;
            case 'limit':
                $limit = (int)$_val;
                break;
            default:
                $smarty->trigger_error("return_article_list: unknown attribute '$_key'");
        }
    }
    if (empty($item)) {
        $smarty->trigger_error("return_article_list: missing 'item' attribute");
    }

    $condition['article_id']        = $article_id;
    $condition['except_article_id'] = $except_article_id;
    $condition['cover']             = $cover;
    $condition['if_top']            = $if_top;

    $list = $sys->return_article_list($limit, $condition);
    if (!empty($list)) {
        foreach ($list as $v) {
            $list_article_id[] = $v['id'];
        }
    }
    $smarty->assign($item, $list);
    if (!empty($list_article_id)) {
        $smarty->assign($item."_id", implode(",", $list_article_id));
    }
    return;
}
$t->register_function("return_article_list", "smarty_function_return_article_list");

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.return_friendlink_info.php
 * Type:     function
 * Name:     return_friendlink_info
 * Purpose:  return friendlink_info
 * -------------------------------------------------------------
 */
function smarty_function_return_friendlink_info($params, &$smarty)
{
    global $sys;
    $_output = '';

    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'item':
                $item = (string)$_val;
                break;
            case 'friendlink_id':
                $friendlink_id = (int)$_val;
                break;
            default:
                $smarty->trigger_error("return_friendlink_info: unknown attribute '$_key'");
        }
    }
    if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
        $smarty->trigger_error("return_friendlink_info: missing 'item' attribute");
    }
    if ( $friendlink_id == "0") {
        $smarty->trigger_error("return_friendlink_info: missing 'friendlink_id' attribute");
    }
    $smarty->assign($item, $sys->return_friendlink_info($friendlink_id));
    return;
}
$t->register_function("return_friendlink_info", "smarty_function_return_friendlink_info");

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.return_friendlink_list.php
 * Type:     function
 * Name:     return_friendlink_list
 * Purpose:  return friendlink_list
 * -------------------------------------------------------------
 */
function smarty_function_return_friendlink_list($params, &$smarty)
{
    global $sys;
    $_output            = '';
    $condition          = array();
    $list_friendlink_id = array();

    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'item':
                $item = (string)$_val;
                break;
            case 'friendlink_id':
                $friendlink_id = (string)$_val;
                break;
            case 'except_friendlink_id':
                $except_friendlink_id = (string)$_val;
                break;
            case 'cover':
                $cover = (int)$_val;
                break;
            case 'if_top':
                $if_top = (int)$_val;
                break;
            case 'limit':
                $limit = (int)$_val;
                break;
            default:
                $smarty->trigger_error("return_friendlink_list: unknown attribute '$_key'");
        }
    }
    if (empty($item)) {
        $smarty->trigger_error("return_friendlink_list: missing 'item' attribute");
    }

    $condition['friendlink_id']         = $friendlink_id;
    $condition['except_friendlink_id']  = $except_friendlink_id;
    $condition['cover']                 = $cover;
    $condition['if_top']                = $if_top;

    $list = $sys->return_friendlink_list($limit, $condition);
    if (!empty($list)) {
        foreach ($list as $v) {
            $list_friendlink_id[] = $v['id'];
        }
    }
    $smarty->assign($item, $list);
    if (!empty($list_friendlink_id)) {
        $smarty->assign($item."_id", implode(",", $list_friendlink_id));
    }
    return;
}
$t->register_function("return_friendlink_list", "smarty_function_return_friendlink_list");

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.return_channel_info.php
 * Type:     function
 * Name:     return_channel_info
 * Purpose:  return channel_info
 * -------------------------------------------------------------
 */
function smarty_function_return_channel_info($params, &$smarty)
{
    global $sys;
    $_output = '';

    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'item':
                $item = (string)$_val;
                break;
            case 'channel_id':
                $channel_id = (int)$_val;
                break;
            default:
                $smarty->trigger_error("return_channel_info: unknown attribute '$_key'");
        }
    }
    if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
        $smarty->trigger_error("return_channel_info: missing 'item' attribute");
    }
    if ( $channel_id == "0") {
        $smarty->trigger_error("return_channel_info: missing 'channel_id' attribute");
    }
    $smarty->assign($item, $sys->return_channel_info($channel_id));
    return;
}
$t->register_function("return_channel_info", "smarty_function_return_channel_info");

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.return_channel_manage.php
 * Type:     function
 * Name:     return_channel_manage
 * Purpose:  return_channel_manage
 * -------------------------------------------------------------
 */
function smarty_function_return_channel_manage($params, &$smarty)
{
    global $sys;
    $_output = '';

    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'item':
                $item = (string)$_val;
                break;
            case 'channel_id':
                $channel_id = (int)$_val;
                break;
            default:
                $smarty->trigger_error("return_channel_manage: unknown attribute '$_key'");
        }
    }
    if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
        $smarty->trigger_error("return_channel_manage: missing 'item' attribute");
    }
    if ( $channel_id == "0") {
        $smarty->trigger_error("return_channel_manage: missing 'channel_id' attribute");
    }
    $smarty->assign($item, $sys->return_channel_manage($channel_id));
    return;
}
$t->register_function("return_channel_manage", "smarty_function_return_channel_manage");

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.return_channel_list.php
 * Type:     function
 * Name:     return_channel_list
 * Purpose:  return channel_list
 * -------------------------------------------------------------
 */
function smarty_function_return_channel_list($params, &$smarty)
{
    global $sys;
    $_output = '';

    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'item':
                $item = (string)$_val;
                break;
            case 'channel_id':
                $channel_id = (int)$_val;
                break;
            case 'limit':
                $limit = (int)$_val;
                break;
            default:
                $smarty->trigger_error("return_channel_list: unknown attribute '$_key'");
        }
    }
    if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
        $smarty->trigger_error("return_channel_list: missing 'item' attribute");
    }
    if ( $channel_id == "0") {
        $smarty->trigger_error("return_channel_list: missing 'channel_id' attribute");
    }
    $smarty->assign($item, $sys->return_channel_sub($channel_id, $limit));
    return;
}
$t->register_function("return_channel_list", "smarty_function_return_channel_list");
?>